package org.sy.lab.多线程基础._3_同步辅助类._3_CyclicBarrier同步屏障;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class Crowdfunding {
	
	private CyclicBarrier cyclicBarrier;
	
	public Crowdfunding(int num, Runnable runnable) {
		cyclicBarrier = new CyclicBarrier(num, runnable);
	}
	
	public void join(String name) {
		
		System.out.println("当前参与人数：" + cyclicBarrier.getNumberWaiting());
		System.out.println(name + "参与众筹");
		try {
			cyclicBarrier.await();
		} catch (InterruptedException | BrokenBarrierException e) {
			e.printStackTrace();
		}
		System.out.println(name + "完成众筹");
	}
}
